package org.igeek.config.bean.ch04;

import org.igeek.config.bean.ch03.Employee;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import java.util.Arrays;

/**
 * @package org.igeek.config.ch04
 * @Description 函数式风格
 * @Author LittlePunk [296526219@qq.ccom]
 * @Version 2022.1
 * @Date 2023/11/14 9:52
 *
 *GenericApplicationContext函数式风格：
 * GenericApplicationContext+Supplier<>供给型接口
 * supplier的返回值作为参数传入registerBean
 */
public class GenericApplicationContextTest {
    public static void main(String[] args) {
        //1.创建ioc容器
        //AnnotationConfigApplicationContext extends GenericApplicationContext
        AnnotationConfigApplicationContext ac =
                new AnnotationConfigApplicationContext();

        //2.注册实例bean
        //ac.registerBean(实例的beanid，实例的类类型，存入到ioc中的实例)
        ac.registerBean("emp2", Employee.class,()->new Employee("hahahah","1234"));
        //刷新
        ac.refresh();

        //3.获取实例bean
        String[] beanDefinitionNames = ac.getBeanDefinitionNames();
        System.out.println("Arrays.toString(beanDefinitionNames) = " + Arrays.toString(beanDefinitionNames));
        Employee emp2 = ac.getBean("emp2", Employee.class);
        System.out.println("emp2 = " + emp2);

    }
}
